package com.sky.controller.admin;

import com.sky.constant.ShopConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "店铺相关接口")
public class ShopController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @ApiOperation("获取店铺状态")
    @GetMapping("/status")
    public Result getStatus(){
        String shop_status = stringRedisTemplate.opsForValue().get(ShopConstant.SHOP_STATUS);
        return Result.success(Integer.parseInt(shop_status));
    }

    @PutMapping("/{status}")
    @ApiOperation("修改店铺状态")
    public Result setShopStatus(
            @ApiParam(value = "店铺营业状态 1(营业), 0(打样))", required = true)
            @PathVariable("status") String status){
        stringRedisTemplate.opsForValue().set(ShopConstant.SHOP_STATUS, status);
        return Result.success();
    }
}
